//
//  ClassMethodsViewController.m
//  安好
//
//  Created by 冯凯 on 14-10-27.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "ClassMethodsViewController.h"

@interface ClassMethodsViewController ()

@end

@implementation ClassMethodsViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma- mark 加解密的类
/**
 *  类方法加密
 *
 *  @param encrypt 加密的字符串，根据这个字符串加密
 *
 *  @return 返回加密的结果
 */
+ (NSString *)encrypt:(NSString *)encrypt;
{
    NSString * encryptKey = @"fengkai";
    
    ER3DESEncrypt *encryptCustomKey = [[ER3DESEncrypt alloc] initWithKey:encryptKey];
    
    return [encryptCustomKey encryptString:encrypt];
    
}
/**
 *  类方法解密
 *
 *  @param decode 解密的字符串，根据这个字符串解密
 *
 *  @return 返回解密的结果
 */
+ (NSString *)decode:(NSString *)decode
{
    NSString * decodeKey = @"fengkai";
    
    ER3DESEncrypt *encryptCustomKey = [[ER3DESEncrypt alloc] initWithKey:decodeKey];
    
    return [encryptCustomKey encryptString:decode];
}
#pragma -mark UTF8的转换
/**
 *  UTF8转换
 *
 *  @param input UTF8的字符串
 *
 *  @return UTF8的转换结果
 */
+ (NSString *)encodeURL:(NSString *) input
{
    NSString *outputStr = (NSString *)
    CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                              (CFStringRef)input,
                                                              NULL,
                                                              (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                              kCFStringEncodingUTF8));
    
    if (outputStr) {
        return outputStr;
    }
    return @"";
}
#pragma - mark 颜色的转换
/**
 *  类方法  获取颜色
 */
+ (UIColor *)colorWithHexString:(NSString *)color
{
    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    if ([cString length] < 6) {
        return [UIColor clearColor];
    }
    if ([cString hasPrefix:@"0X"])
        cString = [cString substringFromIndex:2];
    if ([cString hasPrefix:@"#"])
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6)
        return [UIColor clearColor];
    NSRange range;
    range.location = 0;
    range.length = 2;
    NSString *rString = [cString substringWithRange:range];
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
}


/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
@end
